package com.jinandi.app.service;

import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jinandi.app.dao.OrganizationDao;
import com.jinandi.app.domain.Authorit;
import com.jinandi.app.domain.Organization;

@Service
public class OrganizationService extends BaseService {

	private OrganizationDao organizationDao;

	@Autowired
	public void setOrganizationDao(OrganizationDao organizationDao) {
		this.organizationDao = organizationDao;
	}

	@PostConstruct
	@Transactional
	public void init() {
		List<Organization> list = organizationDao.getOrgByCn("root");
		if (null == list || list.isEmpty()) {
			Organization org = new Organization();
			org.setCn("root");
			org.setName("根");
			org.setPath("/root");
			organizationDao.save(org);
		}
	}

	/**
	 * <根据ID查子>
	 * @param pid
	 * @return
	 * @author CGC 
	 * 创建日期:2013-5-14 下午1:44:10
	 */
	public List<Organization> getOrgChildrenByPid(Long pid){
		return organizationDao.getOrgChildrenByPid(pid);
	}

	/**
	 * 
	 * <找到根>
	 * @return
	 * @author CGC 
	 * 创建日期:2013-5-14 下午1:43:50
	 */
	public List<Organization> getOrgRoot() {
		return organizationDao.getOrgRoot();
	}

	/**
	 * <组织机构列表>
	 * @param params
	 * @param map
	 * @return
	 * @author CGC 
	 * 创建日期:2013-5-14 下午1:49:04
	 */
	public Page<Organization> findOrganizationList(Map<String, Object> params,
			Map<String, String> map) {
		Page<Organization> page= organizationDao.findAll(new Organization().getSpecification(params), getPageRequest(map));
		return page;
	}
}
